import java.util.Random;

import javax.swing.JOptionPane;

public class Challenge8
{
	
	public static void main(String[] args)
	{
		Random randomNumberGenerator = new Random();
		int guesscountc = 0;
		int guesscountw = 0;
		//int randomnum;
		int answer;
		answer = randomNumberGenerator.nextInt(100)+1;
		String guess = "";
		while(!guess.equals ("q"))
				{
		guess = JOptionPane.showInputDialog("Guess a random number between 1 and 100");
		
		try
		{
			int guessint = Integer.parseInt(guess);
			
			if(guessint == answer)
			{
				JOptionPane.showMessageDialog(null, "Good guess! You got it right!");
				guesscountc++;
				answer = randomNumberGenerator.nextInt(100)+1;
				JOptionPane.showMessageDialog(null, "Right guesses: " + guesscountc + "\n Incorrect guesses: " + guesscountw);
			}
			else
			{
				JOptionPane.showMessageDialog(null, "You got it wrong!");
				guesscountw++;
				if(guessint > answer)
				{
					JOptionPane.showMessageDialog(null, "The guess is too high!");
				}
				else
				{
					JOptionPane.showMessageDialog(null, "The guess is too low");
				}
				JOptionPane.showMessageDialog(null, "Right guesses: " + guesscountc + "\n Incorrect guesses: " + guesscountw);
			}
		}
		catch(Exception e)
		{
			if(guess.equals ("q"))
				{
				JOptionPane.showMessageDialog(null, "You quit.");
				}
			else
			{
			JOptionPane.showMessageDialog(null, "That was NOT a number.");
			}
		}
				}
	}
}
